package com.itheima.myreflect2.Student.mapdemo1;

/**
 * @program: Myset
 * @description: 学习Java可变参数
 * @author: xuejingjing
 * @create: 2021-07-19 16:52
 **/

import java.util.HashMap;

/**
 * 1.Object类中有一个方法可以获取对象的哈希值
 * 2.对象的哈希值的特点：
 * 如果没有重写hashCode方法，那么是根据对象的地址值计算出的哈希值。
 * 同一个对象多次调用hashCode()方法返回的哈希值是相同的，不同对象的哈希值是不一样的。
 *
 *如果重写了hashCode方法，一般都是通过对象的属性值计算出哈希值。
 * 如果不同的对象属性值是一样的，那么计算出来的哈希值也是一样的。
 */
public class StudentTestMethod{

    //定义输出考试学生的人数及姓名的方法
    public void show(String...names){
        int length = names.length;
        System.out.println("本次参加考试的人员共有"+length+",名单如下：");
        for (int i = 0; i < length ; i++) {
            System.out.println(names[i]);
        }
    }

    /**
     * Returns a hash code value for the object. This method is
     * supported for the benefit of hash tables such as those provided by
     * {@link HashMap}.
     * <p>
     * The general contract of {@code hashCode} is:
     * <ul>
     * <li>Whenever it is invoked on the same object more than once during
     * an execution of a Java application, the {@code hashCode} method
     * must consistently return the same integer, provided no information
     * used in {@code equals} comparisons on the object is modified.
     * This integer need not remain consistent from one execution of an
     * application to another execution of the same application.
     * <li>If two objects are equal according to the {@code equals(Object)}
     * method, then calling the {@code hashCode} method on each of
     * the two objects must produce the same integer result.
     * <li>It is <em>not</em> required that if two objects are unequal
     * according to the {@link Object#equals(Object)}
     * method, then calling the {@code hashCode} method on each of the
     * two objects must produce distinct integer results.  However, the
     * programmer should be aware that producing distinct integer results
     * for unequal objects may improve the performance of hash tables.
     * </ul>
     * <p>
     * As much as is reasonably practical, the hashCode method defined by
     * class {@code Object} does return distinct integers for distinct
     * objects. (This is typically implemented by converting the internal
     * address of the object into an integer, but this implementation
     * technique is not required by the
     * Java&trade; programming language.)
     *
     * @return a hash code value for this object.
     * @see Object#equals(Object)
     * @see System#identityHashCode
     */
    @Override
    public int hashCode() {
        return super.hashCode();
    }

    public static void main(String[] args) {

        StudentTestMethod student = new StudentTestMethod();

        //根据对象地址值计算出来的哈希值。
        int i = student.hashCode();
        System.out.println("======"+i); /*1112280004*/



        student.show("张三","李四");
        student.show("王五");
        student.show("李粤汉","丁春秋","黄某人");


//        boolean isFirst1 = false;
//        boolean isFirst2 = true;
//        boolean isFirst3 = 1;
//        System.out.println("===="+isFirst);
    }
}
